package battleships;

class Ship {
	private int x,y,length;
	boolean horizontal;
	
	Ship(int x, int y, int length, boolean horizontal) {
		super();
		this.x = x;
		this.y = y;
		this.length = length;
		this.horizontal = horizontal;
	}
	
	@Override
	public String toString() {
		return (horizontal ? "1" : "0") + length + x + y;
	}

	public boolean containsCoordinate(int x, int y) {
		if (horizontal) 
			return this.x == x && this.y <= y && y < this.y + length;
		else
			return this.y == y && this.x <= x && x < this.x + length;
	}
	
	public boolean gotAll(boolean[][] bombed) {
		for (int d = 0; d < length; d++) {
			if (horizontal && !bombed[x][y+d])
				return false;
			if (!horizontal && !bombed[x+d][y])
				return false;
		}
		return true;
	}
}
